package dbz.domain.attack;

import java.util.List;

import dbz.domain.Fighter;
import dbz.domain.attack.conditions.AttackCondition;
import dbz.domain.attack.conditions.KiLevelCondition;

public class Attack implements Cloneable {

	private Integer initialDamage;
	private String name;
	private Fighter fighter;
	private List<AttackCondition> conditions;

	public Attack(String attackName, Integer initialDamage, List<AttackCondition> conditions) {
		this.name = attackName;
		this.initialDamage = initialDamage;
		this.conditions = conditions;
	}

	public void teach(Fighter fighter) {
		this.fighter = fighter;
	}
	
	public void attack(Fighter fighter) {
		fighter.takeDamage(initialDamage);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean areConditionsSatisfied() {
		for(AttackCondition condition : conditions) {
			if(!condition.isSatisfied(this, fighter)) {
				return false;
			}
		}
		return true;
	}

	public Integer getInitialDamage() {
		return initialDamage;
	}

	public KiLevelCondition getKiLevelCondition() {
		return findKiLevelCondition();
	}

	private KiLevelCondition findKiLevelCondition() {
		for(AttackCondition condition : conditions) {
			if(condition instanceof KiLevelCondition) {
				return (KiLevelCondition) condition;
			}
		}
		throw new RuntimeException("No ki condition found");
	}

	public Fighter getFighter() {
		return fighter;
	}

	public void setFighter(Fighter fighter) {
		this.fighter = fighter;
	}

	public List<AttackCondition> getConditions() {
		return conditions;
	}

	public void setConditions(List<AttackCondition> conditions) {
		this.conditions = conditions;
	}

	public void setInitialDamage(Integer initialDamage) {
		this.initialDamage = initialDamage;
	}

}
